/**
 * @Description: 设置元素是否 opacity
 * @Author 卞鹏飞 <228443632@qq.com>
 * @create 2023/2/22 16:18
 * @example
 * v-opacity="value"
 */
export default {
  /**
   * 挂载阶段
   * @param {HTMLElement} el
   * @param {{value: *, oldValue: *}} binding
   */
  // eslint-disable-next-line no-unused-vars
  mounted(el, binding) {
    if (el?.nodeType === Node.ELEMENT_NODE) {
      el.style.opacity = binding.value ? 1 : 0
    }
  },

  /**
   * 更新阶段
   * @param {HTMLElement} el
   * @param {{value: *, oldValue: *}} binding
   */
  updated(el, binding) {
    if (JSON.stringify(binding.oldValue) === JSON.stringify(binding.value)) return
    if (el?.nodeType === Node.ELEMENT_NODE) {
      el.style.opacity = binding.value ? 1 : 0
    }
  }
}
